package reflect;

import java.lang.reflect.Method;

/**
 * 调用Person类中所有被注解@AutoRunMethod标注的方法N次
 * 具体次数有注解参数value决定
 */
public class Test4 {
    public static void main(String[] args) throws Exception {
        Class<?> cls = Class.forName("reflect.Person");
        Method[] methods = cls.getDeclaredMethods();
        for (Method method : methods){
            if (method.isAnnotationPresent(AutoRunMethod.class)){
                AutoRunMethod arm = method.getAnnotation(AutoRunMethod.class);
                System.out.println(method.getName()+"调用:"+arm.value()+"次");
                for (int i = 0; i < arm.value(); i++) {
                    method.invoke(cls.newInstance());
                }
            }else {
                System.out.println(method.getName()+"没有被注解");
            }
        }
    }
}
